package Demo12;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-12-21
 * Time: 15:38
 */
/* 请在这里填写答案 */
interface Buy_car{
    public void buy_mycar();
}
class People implements Buy_car{
    private int cash;
    private boolean vip;
    private String username;

    public People(int cash, boolean vip, String username) {
        this.cash = cash;
        this.vip = vip;
        this.username = username;
    }

    @Override
    public void buy_mycar() {
        System.out.println(username+"要买车");
    }

    public int getCash() {
        return cash;
    }

    public boolean isVip() {
        return vip;
    }

    public String getUsername() {
        return username;
    }
}
class ProxySale implements Buy_car {
    private People people;

    public ProxySale(People people) {
        this.people = people;
    }

    @Override
    public void buy_mycar() {
        if(people.isVip()){
            System.out.println(people.getUsername()+"是vip，可以直接购买新车！");
        }
        else {
            if (people.getCash()>=50000){
                System.out.println(people.getUsername()+"买了新车，交易结束!");
            }
            else {
                System.out.println(people.getUsername()+"钱不够，不能购买新车!");
            }
        }
    }
}

public class Main {
    public static void main(String[] args) {
        Buy_car buy1=new ProxySale(new People(0,true,"Tom"));
        Buy_car buy2=new ProxySale(new People(60000,false,"Jack"));
        Buy_car buy3=new ProxySale(new People(40000,false,"Rose"));
        buy1.buy_mycar();
        buy2.buy_mycar();
        buy3.buy_mycar();
    }
}